package com.lianniu.web.product.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.constants.ErrorCode;
import com.lianniu.web.product.dao.IProductShopDao;
import com.lianniu.web.product.model.ProductShopVo;
import com.lianniu.web.product.service.IProductShopService;
import com.lianniu.web.util.StringUtil;
@Service
public class ProductShopServiceImpl implements IProductShopService {
	
	private static final Logger logger = Logger.getLogger(ProductShopServiceImpl.class);
	@Autowired
	IProductShopDao productShopDao;

	@Override
	public BaseResult insertProductShop(ProductShopVo productShop) {
		logger.info("insertProductShop begin");
		logger.info("insertProductShop: input data check begin");
	    logger.info("insertProductShop productShop:" +JSON.toJSONString(productShop));
	    //BaseResult baseResult;
	    /*if (StringUtil.isEmpty(productShop.getSaleMode())) {
	      baseResult = BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }	*/    
	    
	    logger.info("insertProductBrand: input data check end");
	    
	    return BaseResult.success(productShopDao.insertProductShop(productShop));
	}

	@Override
	public BaseResult updateById(ProductShopVo productShop) {
		logger.info("updateById begin");
		logger.info("updateById: input data check begin");
	    logger.info("updateById productShop:" +JSON.toJSONString(productShop));
		return BaseResult.success(productShopDao.updateById(productShop));
	}
	@Override
	public BaseResult deleteById(String id) {
		logger.info("deleteById begin");
		logger.info("deleteById id"+id);
		return BaseResult.success(productShopDao.deleteById(id));
	}

	@Override
	public BaseResult deleteProductShopBatch(String... id) {
		logger.info("deleteProductShopBatch begin");
	    logger.info("deleteProductShopBatch Ids:" +id.toString());
	    logger.info("deleteProductShopBatch: input data check begin");
	   
	    BaseResult baseResult;
	    if (StringUtil.isEmpty(id.toString())) {
	      baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }
	    logger.info("deleteProductShopBatch: input data check end");
	    
	    return BaseResult.success(productShopDao.deleteProductShopBatch(id));
	}

    @Override
    public BaseResult selecctByLastId() {
        logger.info("selecctByLastId begin");
        return BaseResult.success(productShopDao.selecctByLastId());
    }

}
